package com.example.dml.singleton_pattern;

/**
 * @description:双重检查锁的单例模式
 * @author: gaoyang
 * @date: 2021/10/23 11:43
 */
public class LazyDoubleCheckSingleton {

    private volatile static LazyDoubleCheckSingleton lazy = null;

    private LazyDoubleCheckSingleton(){}

    public static LazyDoubleCheckSingleton getInstance(){
        if (lazy==null){
            synchronized (LazyDoubleCheckSingleton.class){
                if (lazy==null){
                    //分配内存给这个对象
                    //初始化对象
                    //设置lazy指向刚分配的内存地址
                    lazy=new LazyDoubleCheckSingleton();
                }
            }
        }
        return lazy;
    }
}
